<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            <el-button
              v-if="isAuth('module:business:client:trace:form')"
              type="success"
              icon="Plus"
              @click="router.push({ name: 'module_business_client_trace_form', query: { client_id: dataForm.client_id } })">
              {{ i18n('common.create') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_table_main">
        <el-table :data="dataList" v-loading="dataListLoading" stripe>
          <el-table-column prop="id" :label="i18n('common.id')" width="70">
          </el-table-column>

          <el-table-column :label="i18n('contact.salesperson')" width="150">
            <template v-slot="scope">
              <dl class="table_dl" v-if="scope.row.user">
                <dt>
                  <el-image class="cx-list-image" :src="scope.row.user.avatar" loading="lazy" lazy>
                    <template #error>
                      <div class="image-slot">
                        <el-icon><Picture /></el-icon>
                      </div>
                    </template>
                  </el-image>
                </dt>
                <dd class="table_dl_dd_all_30">
                  {{ scope.row.user.nickname }}
                </dd>
                <dd class="table_dl_dd_all_16_gray" v-if="scope.row.user.detail">
                  {{ scope.row.user.detail.position }}
                </dd>
              </dl>
            </template>
          </el-table-column>

          <el-table-column :label="$t('client.trace.type')" width="100">
            <template v-slot="scope">
              {{ scope.row.type.text }}
            </template>
          </el-table-column>

          <el-table-column :label="i18n('client.trace.contact_id')" width="100">
            <template v-slot="scope">
              <span v-if="scope.row.contact">{{ scope.row.contact.name }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="content" :label="i18n('client.trace.content')">
            <template v-slot="scope">
              <p class="show-2-line">{{ scope.row.content }}</p>
            </template>
          </el-table-column>

          <el-table-column prop="reminder_date" :label="i18n('client.trace.reminder_date')" width="120">
          </el-table-column>

          <el-table-column prop="create_time" :label="i18n('common.create_time')" width="160">
          </el-table-column>

          <el-table-column :label="i18n('common.handle')" fixed="right" width="200">
            <template v-slot="scope">
              <el-button
                v-if="isAuth('module:business:client:trace:form')"
                type="primary"
                icon="Edit"
                @click="router.push({ name: 'module_business_client_trace_form', query: { id: scope.row.id, client_id: dataForm.client_id } })">
                {{ i18n('common.update') }}
              </el-button>

              <el-button
                v-if="isAuth('module:business:client:trace:delete')"
                type="danger"
                icon="Delete"
                @click="deleteHandle(scope.row.id)">
                {{ i18n('common.delete') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="admin_table_main_pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :page-size="pageSize"
            :total="totalPage"
            :current-page="pageIndex"
            background
            layout="prev, pager, next,jumper,total">
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="client-trace-list">
  import { useBase } from "@/hooks/base/useBase"
  import { useTable } from "@/hooks/table/useTable"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/client/trace')

  const dataForm = reactive({
    client_id: '',
  })

  const {
    dataList,
    pageIndex,
    pageSize,
    totalPage,
    dataListLoading,
    sizeChangeHandle,
    currentChangeHandle,
    getDataList,
    handleStatus,
    deleteHandle,
  } = useTable(model.value, dataForm)

  onMounted(() => {
    dataForm.client_id = query.id

    getDataList(model)
  })
</script>
